package com.tarena.luban.worker.server.controller;

import com.alibaba.fastjson.JSON;
import com.tarena.luban.worker.server.assemble.WorkerAssemble;
import com.tarena.luban.worker.server.bo.WorkerBO;
import com.tarena.luban.worker.server.service.WorkerService;
import com.tarena.luban.worker.server.vo.WorkerVO;
import com.tarena.passport.protocol.LoginUser;
import com.tarena.tp.luban.worker.server.dto.param.WorkerCreateParam;
import com.tedu.inn.protocol.exception.BusinessException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.params.shadow.com.univocity.parsers.annotations.Headers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@Slf4j
public class WorkerController {
    @Autowired
    private WorkerService workerService;
    @PostMapping("/worker/create")
    //不添加RequestBody注解springmvc默认解析参数 form个数 username=&password=
    public Long createWorker(@RequestBody WorkerCreateParam workerCreateParam,
                             HttpServletRequest request) throws BusinessException {
        return workerService.create(workerCreateParam);
    }
    /**
     * 师傅详情查询
     */
    @Autowired
    private WorkerAssemble workerAssemble;
    @GetMapping("worker/detail")
    public WorkerVO detail() throws BusinessException {
        //1. 业务层返回数据 无法返回VO 返回的是BO
        WorkerBO workerBO=workerService.detail();
        //2. 接口层 也要转化类型 assemble
        //思考一个问题: 如果用户登录了,但是还没有申请入驻师傅 worker查不到的?
        //workerBO是null 或者 单独创建new一个 都会在assemble的时候 出现空指针异常
        return workerAssemble.assembleBO2VO(workerBO);
    }
}
